<!-- 入库订单 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />


    <ex_super_table_page v-bind="option" ref="SuperTablePage" @search="searchChange"
      @selection-change="e => selection = e">
    </ex_super_table_page>


    <ex_super_dialog_form ref="lackGoodsDialog" v-bind="lackGoodsDialog" @afterSubmitSuccess="reload()">
    </ex_super_dialog_form>

    <el-dialog :title="$tt('title_new_outbound_oder_type')" :visible.sync="dialogCreateOrderType"
      custom-class="dialog_small">

      <div class="flex_center dialogCreateOrderType">

        <div class="mg_2">
          <el-button @click="creatOrder('SALES_OUTBOUND')" type="primary" size="medium">{{ $tt('label_sale_outbound')
            }}</el-button>
        </div>
      </div>

    </el-dialog>
    <ex_super_dialog_form ref="dialogImport" v-bind="dialogImport" @afterSubmitSuccess="dialogImportSubmitAfter"
      destroy-on-close>
    </ex_super_dialog_form>

    <ex_super_dialog_form ref="dialogFaceUpload" v-bind="dialogFaceUpload" @afterSubmitSuccess="reload()"
      destroy-on-close>
    </ex_super_dialog_form>
    <!-- <el-dialog :title="$t('tip_please_select_operate_way')" :visible.sync="dialogImportVisible"
      custom-class="dialog_small">

      <div class="mg_2" v-for="item in $enumOptions['BizTypeEnum']">
        <el-button @click="uploadImportFile(files, item)" type="primary" size="big">
          {{ $enumShow(item, 'BizTypeEnum') }}</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>
<script>
import business_function from "@/common/business_function";
import moment from 'moment-mini-ts'
import superTablePageFunction from '@/mixin/super-table-page-function';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'order>>outbound_manage'
import page_table_model_manage from '@/mixin/page_table_model_manage';
export default {

  title: "title_outbound_order",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: {},


  data() {
    return {


      outStatus: "",
      selection: [],
      dialogCreateOrderType: false,
      orderData: {
        draftCount: null,
        getTrackCount: null,
        getTrackFailCount: null,
        partialCount: null,
        processCount: null,
        completeOutCount: null,
        completedCount: null,
        exceptionCount: null,
        invalidCount: null,
      },
      status_map: {
        "DRAFT": 'draftCount',
        'GET_TRACK_NUMBER': 'getTrackCount',
        "GET_TRACK_NUMBER_FAIL": 'getTrackFailCount',
        "WAREHOUSE_PROCESSING": 'processCount',
        "COMPLETE_OUTBOUND": 'completeOutCount',
        "COMPLETED": 'completedCount',
        "EXCEPTION": 'exceptionCount',
        "INVALID": 'invalidCount',
      },
      limitDate: null,
      option: {
        search: {
          formDataHandle: (data) => {
            const out = _.cloneDeep(data)
            if (out.outStatus != 'WAREHOUSE_PROCESSING') {
              delete out.subStatus
            }
            if (out.daterange.length >= 2 && (!out.outOrderNos && !out.platformOrderNo)) {
              out.startTime = out.daterange[0]
              out.endTime = out.daterange[1]
            }
            return out
          },
         
          default: {
            ownerlessFlag: "N",
            outStatus: "",
            daterange: [moment().set({ 'hours': 0, 'minutes': 0, 'seconds': 0, 'milliseconds': 0 }).subtract(3, 'months').valueOf(), moment().set({ 'hours': 23, 'minutes': 59, 'seconds': 59, 'milliseconds': 0 }).valueOf()]
          },
          model: [
            {
              key: 'outStatus', label: 'label_status', itemClass: "w_fill",
              render: (h, { data }) => {
                let enums = Object.keys(this.status_map)//this.$enumOptions['OmsOutboundOrderStatusEnum'] || []
                const list = enums.map(it => (
                  <el-radio-button key={it} label={it}>
                    {this.$enumShow(it, 'OmsOutboundOrderStatusEnum')}
                    {this.status_map[it] && this.orderData[this.status_map[it]] ? `(${this.orderData[this.status_map[it]]})` : "(0)"}
                  </el-radio-button>
                ))
                return (<el-radio-group value={data.outStatus}
                  onInput={e => {
                    this.$set(data, 'outStatus', e)
                    this.$refs.SuperTablePage.loadDataForSearch()
                  }}>
                  <el-radio-button key="" label="">
                    {this.$tt("label_all")}
                  </el-radio-button>
                  {list}
                </el-radio-group>
                )
              }
            },
            {
              label: "label_order_code", key: "outOrderNos", attrs: {
                placeholder: 'tip_input_can_comma_separated'
              }
            },
            { label: "label_platform_code", key: "platformOrderNo", },
            { label: "label_outbound_type", key: "outType", type: 'select', enum: 'OmsOutboundOrderTypeEnum', },


            { label: "label_customer", key: "customerIds", type: 'common_customer_choose', multiple: true, },

            {
              label: "label_time_range", key: "daterange", type: 'date-picker', fold: false,
              attrs: {
                clearable: false,
                type: 'datetimerange', 'default-time': ['00:00:00', '23:59:59'],
                'popper-class': "no_clear_range_picker",
                'picker-options': {
                  shortcuts: this.$date_range_shortcuts(),
                  onPick: (d) => {
                    this.limitDate = d.minDate
                  },
                  disabledDate: (t) => {
                    if (moment(t).isAfter(moment().set({ 'hours': 23, 'minutes': 59, 'seconds': 59, 'milliseconds': 999 }))) return true
                    if (this.limitDate != null) {
                      if (moment(t).isAfter(moment(this.limitDate).add(3, 'months')) ||
                        moment(t).isBefore(moment(this.limitDate).subtract(3, 'months'))) {
                        return true
                      }
                    }
                    return false
                  }
                },
              },
              on: {
                blur: () => { this.limitDate = null }
              }
            },
            { label: "label_is_lack_goods", key: "stockOutFlag", type: 'select', enum: 'YesOrNoEnum', fold: true, },

            { label: "label_consignee_person_name", key: "consignee", fold: true, },
            { label: "label_sku", key: "skuId", type: 'sku_selec_input', fold: true, },
            { label: "OmsOutboundOrderStatusEnum__WAREHOUSE_PROCESSING", if: (data) => data.outStatus == 'WAREHOUSE_PROCESSING', key: "subStatus", type: 'select', enum: 'OmsOutboundProcessingStatusEnum', fold: true, },
            { key: 'warehouseId', label: 'label_outbound_warehouse', type: 'base_warehouse_select', fold: true },
            { key: 'trackNumber', label: 'label_track_code', fold: true },
          ],
        },
        actionExtra: [
          {
            label: 'label_lack_goods_handle',
            // if: () => ['EXCEPTION'].includes(this.outStatus),
            auth: 'oms_outbound_order_lack_goods_handle',
            click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))
              if (this.selection.some(row => !['Y'].includes(row.stockOutFlag))) {
                return this.$message.error(this.$t("tip_part_order_status_error_no_operate"))
              }
              this.lackGoodsHandle(this.selection)
            }
          },

          {
            label: "label_face_track_upload",
            auth: 'oms_outbound_order_face_track_upload',
            click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))
              if (this.selection.length != 1) {
                return this.$message.error(this.$t("label_only_select_count_order", { count: 1 }))
              }
              this.$refs.dialogFaceUpload.showNew(
                {
                  title: this.$tt("label_face_track_upload"),
                  data: {
                    ..._.head(this.selection),
                    files: [],
                  },
                  onlySetData: true
                },)
            },
          },
          {
            label: { _key: 'label_type_download_import_temp', type: "" },
            type: "more", buttonAttrs: { type: "normal" },
            list: this.$enumOptions['BizTypeEnum'].map(it => ({
              label: this.$enumShow(it, 'BizTypeEnum'),
              click: () => this.downloadImportTemp(it)
            }))
          },
          {
            label: 'label_import', click: () => {
              this.$refs.dialogImport.showNew(
                {
                  title: this.$tt(['label_import', 'label_outbound_order']),
                  data: {
                    files: [],
                  },
                  onlySetData: true
                },)
            }
          },
          {
            label: { _key: 'label_export', type: "" },
            type: "more", buttonAttrs: { type: "normal" },
            list: [
              {
                label: 'label_outbound_order_list',
                click: () => this.exportExcel('list')
              }, {
                label: 'label_outbound_order_detail',
                click: () => this.exportExcel('detail')
              }
            ]
          },
          // {
          //   render: (h) => (<button_select_file onInput={files => this.uploadImportFileWaySelect(files)} type="primary">
          //     {this.$tt(['label_import', 'label_outbound_order'])}
          //     <i class="el-icon-upload2 el-icon--right"></i>
          //   </button_select_file>),
          // },
          // { label: 'label_cutoff_order', attrs: { type: "warning" }, click: () => this.batchCutoffOrder(this.selection), },
          { label: 'label_batch_submit_order', attrs: { type: "primary" }, auth: 'oms_outbound_order_edit', click: this.batchSubmitOrder },
          { label: 'title_new_outbound_oder', attrs: { type: "primary" }, auth: 'oms_outbound_order_edit', click: () => this.creatOrder() },
        ],
        table: {
          url: "/oms-api/order/OutboundOrderRpc/selectListPage.json",

          urlParams: (params) => {
            // params.ownerlessFlag = "N"
            if (this.outStatus) {
              return Object.assign(params, { outStatus: this.outStatus })
            }
            return params

          },
          model: this.init_table_model(),
        }
        ,
      },
      dialogImport: {
        customClass: 'dialog_auto',
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          model: [
            { key: 'bizType', label: 'label_business_type', type: "radio-group", enum: 'BizTypeEnum' },
            {
              key: 'files', label: 'label_file_upload',
              render: (h, { data }) => {
                return h('el-upload', {
                  props: {
                    action: "none", 'auto-upload': false, limit: 1,
                    'on-change': (file, files) => {
                      this.$set(data, 'files', files)
                    },
                    'on-exceed': () => this.$message.error(this.$tt("label_only_select_count_file", { count: 1 })),
                  }
                }, [(<el-button slot="trigger" size="small" type="primary">{this.$t('label_select_file')}</el-button>)])
              }
            },

          ],
          rules: {
            'bizType': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'files': [{ required: true, type: "array", message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
          },
        }
      },
      lackGoodsDialog: {
        customClass: 'dialog_auto',
        submitUrl: '/oms-api/order/OutboundOrderRpc/handlerOrderShipment.json',
        submitDataHandle: (data) => {
          return {
            orderIds: data.orderIds,
            stockOutHandle: data.stockOutHandle,
          }
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          model: [
            {
              key: 'customerName', label: 'label_customer_info', formType: 'text',
              render: (h, { data, item }) => {
                const unionRows = _.uniqBy(data.rows ? data.rows : [], it => it.customerId)
                return (<div style="max-height: 300px;overflow-y:auto;">
                  {unionRows.map(it => (<div>{this.$formatNameCode(it.customerName, it.customerCode)}</div>))}
                </div>)
              },
            },
            {
              key: 'orderNo', label: 'label_order_code', formType: 'text',
              render: (h, { data, item }) => {
                const unionRows = data.rows ? data.rows : []
                return (<div style="max-height: 300px;overflow-y:auto;">
                  {unionRows.map(it => (<div>{it.orderNo}</div>))}
                </div>)
              },
            },
            {
              key: 'stockOutHandle', label: 'label_lack_goods_handle',
              type: "select", enum: "OutboundStockOutHandleTypeEnum",
            },
          ],
          rules: {
            'stockOutHandle': [{ required: true, message: this.$tt('tip_can_no_empty'), }],
          },
        }
      },
      dialogFaceUpload: {
        customClass: 'dialog_auto',
        submitUrl: "/oms-api/order/OutboundOrderRpc/updateLabelOssPath.json",
        submitDataHandle: (data) => {
          return {
            orderNo: data.orderNo,
            labelOssPath: data.files[0].filePath,
          }
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          model: [
            { key: 'orderNo', label: 'label_order_code', formType: "text" },
            {
              key: 'files',
              label: 'label_face_track',
              rules: (data) => {
                return {
                  required: true,
                  validator: (r, v, cb) => {
                    if (data.isUpload) {
                      cb(this.$tt("label_uploading"))
                    } else if (_.isEmpty(data.files)) {
                      cb(this.$tt("tip_can_no_empty"))
                    } else {
                      cb()
                    }
                  }
                }
              },
              render: (h, { data }) => {
                return (<ex_super_upload value={data.files} type="file" accept=".pdf"
                  onInput={e => this.$set(data, 'files', e)}
                  onIsUploadChange={e => this.$set(data, 'isUpload', e)}
                  limit={1} headers={{ targetFolder: 'oms/face_track' }}
                />)
              },

            },

          ],
          rules: {

          },
        }
      },
    };
  },



  methods: {

    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },
        {
          key: 'orderNo', label: 'label_order_code', 'min-width': 170,
        },
        { key: 'ecPlatformOrderNo', label: 'label_ec_platform_code', 'width': 170, },
        { key: 'customerName', label: 'label_customer_name', 'width': 100, 'show-overflow-tooltip': true, },
        { key: 'customerCode', label: 'label_customer_code', 'width': 100, 'show-overflow-tooltip': true, },
        { key: 'bizType', label: 'label_business_type', 'width': 100, formatter: (r, c, v) => this.$enumShow(v, "BizTypeEnum") },

        {
          key: 'outType', label: 'label_outbound_type', 'width': 120, 'show-overflow-tooltip': true,
          render: (h, s) => this.$renderText(h, s, { enum: 'OmsOutboundOrderTypeEnum', valueClassMap: { "DESTROY_OUTBOUND": "color_danger" } })
        },
        {
          key: 'outStatus', label: 'label_order_status', 'width': 120, 'show-overflow-tooltip': true,
          render: (h, s) => this.$renderText(h, s, {
            enum: 'OmsOutboundOrderStatusEnum', valueClassMap: {
              "COMPLETE_OUTBOUND": "color_success", "CANCELED": "color_info", INVALID: "color_info",
              GET_TRACK_NUMBER_FAIL: "color_danger",
              INITIATE_INTERCEPT: "color_warning", INTERCEPT: "color_warning",
              INTERCEPT_FAIL: "color_warning", INTERCEPT_SUCCEED: "color_warning",
            }
          }),
        },
        { key: 'ecPlatform', label: 'label_ec_platform', 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "OmsOutboundOrderEcPlatformEnum") },
        { key: 'warehouseCode', label: 'label_outbound_warehouse', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'logisticsName', label: 'label_logistics', 'min-width': 140, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$formatNameCode(v, r.logisticsCode) },
        { key: 'trackNumber', label: 'label_track_code', 'min-width': 140, 'show-overflow-tooltip': true, },
        { label: "label_is_lack_goods", key: "stockOutFlag", 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum") },

        {
          key: 'exceptionMsg', label: 'label_exception_info', 'width': 140,
          render: (h, { row, column }) => {
            const code = ['EXCEPTION', 'GET_TRACK_NUMBER_FAIL'].includes(row.outStatus) ? row.exceptionMsg : ''
            if (!code) return ""
            return (<text_extra_tooltip_operate
              value={code} ellipsis
              data_type={column.property} data_id={row.id}
            />)
          },

        },
        { key: 'gmtCreate', label: 'label_create_order_date', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'outDate', label: 'label_outbound_date', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        {
          type: 'operate', width: 170, fixed: 'right', operate: [
            {
              label: "label_edit",
              auth: 'oms_outbound_order_edit',
              //disabled: (row) => row.outStatus != 'DRAFT' && row.outStatus != 'GET_TRACK_NUMBER_FAIL',
              disabled: (row) => !['DRAFT', 'GET_TRACK_NUMBER_FAIL', 'EXCEPTION'].includes(row.outStatus),
              click: (row) => {
                this.editOrder(row)
              }
            },

            {
              label: 'label_delete',
              if: (row) => row.outStatus == "DRAFT",
              type: "confirm-button",
              url: '/oms-api/order/OutboundOrderRpc/deleteOrder.json',
              buttonClass: "button_text_danger", confirmButtonType: 'danger',
              message: 'text_confirm_sure_delete',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },
            {
              type: 'more',
              items: [
                { label: 'label_view_detail', click: (row) => this.clickDetail(row) },
                {
                  label: 'label_order_cancellation',
                  auth: 'oms_outbound_order_cancellation',
                  disabled: (row) => !['GET_TRACK_NUMBER_FAIL', 'WAREHOUSE_PROCESSING', 'WAIT_OUTBOUND'].includes(row.outStatus),
                  click: (row) => this.batchCutoffOrder([row])
                },
                {
                  label: 'label_order_intercept',
                  auth: 'oms_outbound_order_intercept',
                  disabled: (row) => !this.canIntercept([row]),
                  click: (row) => this.interceptOrder([row])
                },
                {
                  label: 'label_copy_new',
                  auth: 'oms_outbound_order_edit',
                  click: (row) => this.copyOrder(row),
                },
                {
                  label: 'label_lack_goods_handle',
                  auth: 'oms_outbound_order_lack_goods_handle',
                  disabled: (row) => !['Y'].includes(row.stockOutFlag),
                  click: (row) => this.lackGoodsHandle([row]),
                },
                {
                  label: "label_face_track_upload",
                  auth: 'oms_outbound_order_face_track_upload',
                  click: (row) => {

                    this.$refs.dialogFaceUpload.showNew(
                      {
                        title: this.$tt("label_face_track_upload"),
                        data: {
                          ...row,
                          files: [],
                        },
                        onlySetData: true
                      },)
                  },
                },
                {
                  label: "label_tms_waybill_check_track",
                  click: (row) => {
                    this.$router.push({ path: '/page/oms/track/track_list', query: { trackNumber: row.orderNo, } })
                  }
                },

              ]
            }
          ],
        }
      ]
    },
    lackGoodsHandle(rows) {
      this.$refs.lackGoodsDialog.showNew({
        title: this.$t("label_lack_goods_handle"),
        // submitType: "form",
        data: {
          rows,
          orderIds: rows.map(it => it.id),
          stockOutHandle: null,
        },
        onlySetData: true,

        submitCallResult: (resultData, data, done) => {
          done(true, true)
          if (resultData.data && resultData.data.failList && !_.isEmpty(resultData.data.failList)) {

            if (_.isEmpty(resultData.data.successOrderNoList)) {
              this.$message.error(this.$tt("tip_all_order_operate_fail"))
            } else {
              this.$message.warning(this.$tt("tip_part_order_operate_fail"))
            }
            this.$msgbox_table({
              note: this.$tt('label_order_failed_to_operate'),
              tableProp: {
                data: resultData.data.failList,
                model: [
                  { key: 'OrderNo', label: 'label_outbound_code', 'min-width': 120, 'show-overflow-tooltip': true, },
                  { key: 'message', label: 'label_info', 'min-width': 120, 'show-overflow-tooltip': true, }
                ],
              },
            }, { type: 'error', customClass: 'dialog_small' })
          } else {
            this.$message.success(this.$tt("tip_submit_success"))
          }
        }
      })
    },
    dialogImportSubmitAfter(data) {
      this.$functionCommon({
        url: data.bizType == 'TOB' ? this.$url['oms/outbound/tob/importExcel'] : this.$url['oms/outbound/toc/importExcel'],
        file: data.files[0].raw,
        commonType: "import",
      })
      // this.$uploadFile({
      //   loading: true,
      //   url: data.bizType == 'TOB' ? this.$url['oms/outbound/tob/importExcel'] : this.$url['oms/outbound/toc/importExcel'],
      //   file: data.files[0].raw,
      //   success: (res) => {
      //     mainFunction.importConfirmMsgBox.call(this)
      //   }
      // })
    },

    downloadImportTemp(bizType) {
      if (this.$clickFast()) return
      this.$downloadFile({
        window: true,
        url: this.$url['oms/outbound/downloadImportTemp'],
        data: {
          bizTypeEnum: bizType
        }
      })
    },
    isSelectable(row) {
      return ['DRAFT', 'GET_TRACK_NUMBER'].some(e => e == row.outStatus)
    },
    editOrder(row) {
      this.$router.push({
        path: '/page/oms/order/outbound/order_operate', query: { id: row.id, edit: true, emitKey }
      })
    },
    copyOrder(row) {
      this.$router.push({
        path: '/page/oms/order/outbound/order_operate', query: { id: row.id, edit: true, copy: true, emitKey }
      })
    },
    clickDetail(row) {

      this.$router.push({
        path: '/page/oms/order/outbound/order_detail', query: { id: row.id, }
      })
    },
    changeOutStatus(e) {
      this.outStatus = e
      this.reload()
    },

    creatOrder(outType) {
      this.$router.push({ path: '/page/oms/order/outbound/order_operate', query: { emitKey, outType } })
      this.dialogCreateOrderType = false
    },
    searchChange(data) {
      this.$ajax({
        url: "/oms-api/order/OutboundOrderRpc/statOrderData.json",
        method: 'post',
        data: data,
        success: (res) => {
          if (res && res.data)
            this.orderData = res.data
        }
      })
    },
    batchSubmitOrder() {
      let _list = this.selection;
      if (_.isEmpty(_list)) return this.$message.error(this.$tt("tip_please_select_order"))
      if (_list.some(it => !['DRAFT', 'GET_TRACK_NUMBER'].some(e => e == it.outStatus))) return this.$message.error(this.$tt("tip_status_error_no_operate"))
      this.$confirm(this.$tt("tip_is_count_order_to_submit", { count: _list.length }), this.$tt('label_tip'), {
        confirmButtonText: this.$tt('label_confirm'),
        cancelButtonText: this.$tt('label_cancel'),
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/oms-api/order/OutboundOrderRpc/batchOmsOutboundOrder.json",
          method: 'post', type: 'json',
          data: { orderIds: _list.map(it => it.id) },
          success: (res) => {
            if (res.data && res.data.failList && !_.isEmpty(res.data.failList)) {

              if (_.isEmpty(res.data.successOrderNoList)) {
                this.$message.error(this.$tt("tip_all_order_operate_fail"))
              } else {
                this.$message.warning(this.$tt("tip_part_order_operate_fail"))
                this.reload()
                this.$emitPage('standard>outbound_manage', 'reload')
              }
              this.$msgbox_table({
                note: this.$tt('label_order_failed_to_operate'),
                tableProp: {
                  data: res.data.failList,
                  model: [
                    { key: 'OrderNo', label: 'label_outbound_code', 'min-width': 120, 'show-overflow-tooltip': true, },
                    { key: 'message', label: 'label_info', 'min-width': 120, 'show-overflow-tooltip': true, }
                  ],
                },
              }, { type: 'error', customClass: 'dialog_small' })
            } else {
              this.$message.success(this.$tt('tip_submit_success'))
              this.reload()
              this.$emitPage('standard>outbound_manage', 'reload')
            }

          }
        })
      }).catch(() => {
      });

    },
    canIntercept(_list) {
      return !_list.some(it => ['COMPLETE_OUTBOUND', 'GET_TRACK_NUMBER', 'GET_TRACK_NUMBER_FAIL', 'DRAFT',
        'EXCEPTION', 'COMPLETED', 'INTERCEPT', 'INVALID', 'SUBMIT_ORDER', 'PARTIAL_OUTBOUND', 'PACKAGE_EXCEPTION'].some(e => e == it.outStatus))
    },
    interceptOrder(_list) {
      if (_.isEmpty(_list)) return this.$message.error(this.$tt('tip_please_select_order'))
      if (!this.canIntercept(_list)) return this.$message.error(this.$tt('tip_status_error_no_operate'))
      const h = this.$createElement
      this.$prompt(h("div", {}, [
        h("div", {}, [this.$tt("label_intercept_order_code") + "：" + _list.map(it => it.orderNo).join(",")]),
        h("div", {}, [this.$tt("label_intercept_instruction") + "：" + this.$tt("tip_intercept_instruction")]),
      ]), this.$tt('label_intercept_reason'), {
        inputPlaceholder: this.$tt('label_intercept_reason'),
        inputValidator: (v) => {
          if (_.isEmpty(_.trim(v))) {
            return this.$tt('tip_can_no_empty')
          } else if (v.length > 200) {
            return this.$tt("tip_maximum_length_characters", { count: 200 })
          }
          return true
        },
        confirmButtonText: this.$tt('label_confirm'),
        cancelButtonText: this.$tt('label_cancel'),
        type: 'warning'
      }).then(({ value }) => {
        this.$ajax({
          url: "/oms-api/order/OutboundOrderRpc/interceptOrder.json",
          method: 'post', type: 'json', loading: true,
          data: { orderId: _list.map(it => it.id).join(","), cause: value },
          success: (res) => {
            if (res.data && res.data.orderInterceptStatus) {
              if (res.data.orderInterceptStatus == "SUCCEED") {
                this.$message.success(this.$enumShow(res.data.orderInterceptStatus, "OrderInterceptStatusEnum"))

              } else if (res.data.orderInterceptStatus == "UNDERWAY") {
                this.$message.warning(this.$enumShow(res.data.orderInterceptStatus, "OrderInterceptStatusEnum"))
              } else {
                this.$message.error(this.$enumShow(res.data.orderInterceptStatus, "OrderInterceptStatusEnum"))
              }
              this.reload()
              this.$emitPage('standard>outbound_manage', 'reload')
            }
          }
        })
      }).catch(() => {
      });

    },
    batchCutoffOrder(_list) {
      if (_.isEmpty(_list)) return this.$message.error(this.$tt('tip_please_select_order'))
      if (_list.some(it => !['GET_TRACK_NUMBER_FAIL', 'WAREHOUSE_PROCESSING', 'WAIT_OUTBOUND'].some(e => e == it.outStatus))) return this.$message.error(this.$tt('tip_status_error_no_operate'))
      this.$prompt(this.$tt("tip_is_count_order_to_cutoff", { count: _list.length }), this.$tt('label_tip'), {
        inputPlaceholder: this.$tt('label_cutoff_reason'),
        inputValidator: (v) => {
          if (_.isEmpty(_.trim(v))) {
            return this.$tt('tip_can_no_empty')
          } else if (v.length > 200) {
            return this.$tt("tip_maximum_length_characters", { count: 200 })
          }
          return true
        },
        confirmButtonText: this.$tt('label_confirm'),
        cancelButtonText: this.$tt('label_cancel'),
        type: 'warning'
      }).then(({ value }) => {
        this.$ajax({
          url: "/oms-api/order/OutboundOrderRpc/cutoffOrder.json",
          method: 'post', type: 'json',
          data: { orderNos: _list.map(it => it.orderNo), reason: value },
          success: (res) => {
            if (res.data && res.data.cutOffErrorOrderList && !_.isEmpty(res.data.cutOffErrorOrderList)) {

              if (_.isEmpty(res.data.successOrderList)) {
                this.$message.error(this.$tt("tip_all_order_operate_fail"))
              } else {
                this.$message.warning(this.$tt("tip_part_order_operate_fail"))
                this.reload()
                this.$emitPage('standard>outbound_manage', 'reload')
              }
              this.$msgbox_table({
                note: this.$tt('label_order_failed_to_operate'),
                tableProp: {
                  data: res.data.cutOffErrorOrderList,
                  model: [
                    { key: 'OrderNo', label: 'label_outbound_code', 'min-width': 120, 'show-overflow-tooltip': true, },
                    { key: 'message', label: 'label_info', 'min-width': 120, 'show-overflow-tooltip': true, }
                  ],
                },
              }, { type: 'error', customClass: 'dialog_small' })
            } else {
              this.$message.success(this.$tt('tip_submit_success'))
              this.reload()
              this.$emitPage('standard>outbound_manage', 'reload')
            }
          }
        })
      }).catch(() => {
      });
    },
    exportExcel(type) {

      if (type === 'detail') {
        if (_.isEmpty(this.selection)) {
          this.$message.error(this.$tt('tip_please_select_order'))
          return
        }
        this.$downloadFile({
          url: '/oms-api/order/OutboundOrderRpc/downloadOrderDetailPdf.json',
          window: false,
          data: { idList: this.selection.map(it => it.id) },
        });
        return
      }
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchFormData(),
        model: this.option.search.model,
        selection: this.selection,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              idList: selection.map(it => it.id)
            }
          } else {
            params = data
          }

          this.$functionCommon({
            url: '/oms-api/order/OutboundOrderRpc/exportOrderExcel.json',
            data: params,
            type: 'json',
          })

        }
      })

    },
  }
};

</script>
<style>
.dialogCreateOrderType .el-button {
  padding: 2rem 4rem;
  font-size: 1.2em;
  font-weight: bold;
}
</style>
